<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <title>修改照顾信息</title>
    <link rel="stylesheet" href="css/bootstrap.css">
    <script src="js/jquery.js" type="text/javascript"></script>
    <script src="js/bootstrap.js" type="text/javascript"></script>
    <script src="js/jsrender.js" type="text/javascript"></script>
    <script src="js/common.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function(){
            var arrayurl = window.location.search.substring(1).split("&")
            var id = arrayurl[0].split("=")[1]
            // var date = arrayurl[0].split("=")[2]
            $.ajax({
                url: GC.bctx + "care/"+ id,
                type: "GET",
                headers: {"Authorization": localStorage.getItem("token")},
                success:function(r){
                    if(r.successed){
                        $("#customerid").val(r.data.customerid)
                        $("#customername").val(r.data.customername)
                        $("#nurseid").val(r.data.nurseid)
                        $("#nursename").val(r.data.nursename)
                    }else{
                        alert(r.message)
                    }
                }
            })
            $("form").submit(function(){
                $.ajax({
                    url: GC.bctx + "care/update/"+id,
                    type:"PUT",
                    data:$("form").serialize(),
                    headers: {"Authorization": localStorage.getItem("token")},
                    success:function(r){
                        if(r.successed){
                            //修改成功，转向显示所有部门页面
                            alert(r.message)
                            window.location.href="cares.html"
                        }else{
                            //修改失败，显示失败信息
                            alert(r.message)
                        }

                    }
                })
                return false
            })

            $("#nurseid").blur(function(){
                // alert($("#nurseID").val())
                if($("#nurseid").val()==""){
                    $("#nursename").val("")
                    return false;
                }
                if($("#nurseid").val()!=""){
                    if(isNaN($("#nurseid").val())){
                        alert("护士编号必须为纯数字!")
                        $("#nursename").val("")
                        return false;
                    }
                    // alert("进入非空")
                    $.ajax({
                        url: GC.bctx + "care/checkNurseID/" + $("#nurseid").val(),
                        type: "GET",
                        headers: {"Authorization": localStorage.getItem("token")},
                        success: function (r) {
                            if (r.successed) {
                                //修改成功，转向显示所有部门页面
                                $("#nursename").val(r.data)
                            } else {
                                //修改失败，显示失败信息
                                alert(r.message)
                                $("#nursename").val("")
                            }
                        }
                    })
                }
            })


        })
    </script>
</head>
<body>
<div class="container-fluid">
    <h1>修改照顾信息</h1>
    <hr/>
    <form>
        <table>
            <tr class="d-none">
                <td >客户编号：</td>
                <td><input id="customerid" name="customerid" type="text" /></td>
                <td><span class="c-r">*</span></td>
            </tr>
            <tr class="d-none">
                <td>客户名：</td>
                <td><input id="customername" class="form-control" name="customername" type="text" readonly="readonly"/></td>
            </tr>
            <tr>
                <td>护士编号：</td>
                <td><input id="nurseid" class="form-control" name="nurseid" type="text"/></td>
                <td><span class="c-r">*</span></td>
            </tr>
            <tr>
                <td>护士名：</td>
                <td><input id="nursename" class="form-control" name="nursename" type="text" readonly="readonly"/></td>
            </tr>
            <tr>
                <td colspan="3" class="text-center">
                    <input type="submit" value="保存"/>
                    <input type="reset" value="重置"/>
                </td>
            </tr>
        </table>
    </form>
</div>
</body>
</html>